// pages/items/items.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
     servers:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that =this
    wx.request({
      url: 'https://www.eddieby.top/gd/public/index.php/index/index/get_servers',
      data: {
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (response) {
        that.setData({
          servers: response.data
        })
      }
    });
  },
  toCall: function(){
    wx.makePhoneCall({
      phoneNumber: '0575-86570592' //仅为示例，并非真实的电话号码
    })
  },
  goRules: function(){
    wx.downloadFile({
      url: 'https://eddieby.top/document/rules.doc',
      success: function (res) {
        var filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      }
    })
  },
  toHelp: function () {
    wx.downloadFile({
      url: 'https://eddieby.top/document/godii.doc',
      success: function (res) {
        var filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      }
    })
  },
  toDown: function () {
    wx.setClipboardData({
      data: 'https://bbbbbbbb.org/byte/byte/public/index.php/index/index/download',
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '网址已复制',
              icon: 'success',
              duration: 1000
            })
          }
        })
      }
    })
    // wx.navigateTo({
    //   url: '../mobile/mobile',
    // })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  qrcode: function (event) {
    wx.request({
      url: 'https://www.eddieby.top/gd/public/index.php/index/index/get_qrcode',
      data: {
        'openid': wx.getStorageSync('openid'),
        'serverid': event.currentTarget.dataset.id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (response) {
        // console.log(response.data)
        if (response.data !='success:false'){
          wx.previewImage({
            current: '', // 当前显示图片的http链接
            urls: [response.data.url] // 需要预览的图片http链接列表
          })
        }else{
          wx.showToast({
            title: '请先购买套餐',
            icon: 'loading',
            duration: 1000
          })
        }
      }
    });
    // console.log(event.currentTarget.dataset.id)
  },
  get_ss:function(event){
    wx.request({
      url: 'https://www.eddieby.top/gd/public/index.php/index/index/get_qrcode',
      data: {
        'openid': wx.getStorageSync('openid'),
        'serverid': event.currentTarget.dataset.id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (response) {
        // console.log(response.data)
        if (response.data != 'success:false') {
          wx.setClipboardData({
            data: response.data.ss,
            success: function (res) {
              wx.getClipboardData({
                success: function (res) {
                  wx.showToast({
                    title: 'ss uri已复制',
                    icon: 'success',
                    duration: 1000
                  })
                }
              })
            }
          })
        }
      }
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})